import {
	ReportPanelActionType,
	ICtrlDataAction,
	ICtrlEvent,
	IReportPanelAbility,
	IReportPanelControllerParams,
	IReportPanelModel,
	IReportPanelStore,
	IParam,
} from '@/core';
import { QXEvent } from 'qx-util';
import { PropType } from 'vue';
import {
	getCtrlClassNames,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 报表输入参数
 *
 * @export
 * @return {*}
 */
export function useReportPanelProps() {
	return {
		...useCtrlProps(),
		openView: Function,
		newView: Function,
		actions: Object as PropType<ICtrlDataAction>,
	};
}

/**
 * 报表基础参数
 *
 * @export
 * @param {IReportPanelModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useReportPanelBasic(model: IReportPanelModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		return getCtrlClassNames(model, props);
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
	};
}

/**
 * 报表部件行为
 *
 * @export
 */
export function useReportPanelAction(controller: any) {
	return {
		...useCtrlAction(controller),
	};
}

/**
 * 报表部件控制器
 *
 * @export
 */
export function useReportPanelControllerParams<
	S extends IReportPanelStore,
	M extends IReportPanelModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<ReportPanelActionType, IReportPanelAbility>>,
	otherParams: IParam = {}
): IReportPanelControllerParams<ReportPanelActionType, IReportPanelAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		actions: props.actions,
		singleSelect: props.singleSelect,
		selectFirstDefault: props.selectFirstDefault,
		openView: props.openView,
		newView: props.newView,
		customParams: otherParams.attrs,
	};
}
